<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建原始需求</title>
    <link href="../css/common.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<!--header-->
<!--header-->
<header id="header" class="header">
    <div class="header-info left"><i></i><a href="pm-need-list.html">需求列表</a> > 创建原始需求 </div>
    <div class="right-user right">
         <div class="clear t" >             <div id="headusername" class="role"></div>             <div class="icon"></div>         </div>
        <div class="head-down">
            <ul><li><a href="edit-pwd.html">修改密码</a></li><li><a onclick="loginOut()">退出系统</a></li></ul></div><div>
    </div>
    </div>
</header>
<!--menu-->
<aside id="aside" class="aside">
    <div class="logo">运营平台</div>
    <ul class="menu" id="asidemenu">
    </ul>
</aside>



<!--content-->
<div class="content">
    <div class="page-inner">
        <div class="page-content">
            <div class="table-head"><i></i>原始需求</div>
            <div class="table-cont">
                <table class="content-table">
                    <tr>
                        <td><span class="red-start">*</span>需求名称：</td>
                        <td colspan="2"><input value="" id="needName" /><a class="error-msg">请填写需求名称！</a></td>

                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>来源：</td>
                        <!--<select id="needSource" onchange="_API.getComeSource('needSide',false,true,$(this).val(),'needSide')"></select>-->
                        <td>
                            <!--<div class="exist-source clear" style="display: block" id="existSourceBox">-->
                                <!--<div class="left">原有来源</div><a class="left edit-source-btn" id="goEditSource">修改</a>-->
                            <!--</div>-->
                            <div class="search-box clear" style="display: block" id="searchBox">

                                <input class="left" placeholder="输入至少两个字" />
                                <a class="left edit-source-btn" id="goSearchBtn">搜索</a>
                                <!--<a class="left edit-source-btn" id="giveUp">放弃</a>-->
                                <select class="left" id="keyMatchSelect" onchange="_API.getComeSource('needSide',false,true,$(this).val())"><option>请输入关键词</option></select>
                            </div>

                        </td>
                        <td><span class="red-start">*</span>需求方：</td>
                        <td><select id="needSide"><option>请选择</option></select><span class="red-start" style="color: #4cae4c">先选择来源</span></td>
                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>类别：</td>
                        <td><select id="typeList"></select></td>
                        <td><span class="red-start">*</span>产品:</td>
                        <td><select id="productList" onchange="_API.getFunctionList('functionList',false,false,'productList')"></select></td>
                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>使用平台：</td>
                        <td><select id="platformList"></select></td>
                        <td><span class="red-start">*</span>功能模块：</td>
                        <td><select id="functionList"><option>请选择</option></select><span class="red-start" style="color: #4cae4c">先选择产品</span></td>
                    </tr>

                    <tr>
                        <td><span class="red-start">*</span>紧急程度：</td>
                        <td><select id="levelList"></select></td>

                    </tr>
                    <tr class="area">
                        <td><span class="red-start">*</span>需求场景：</td>
                        <td colspan="3">
                            <textarea id="scenario"></textarea>
                        </td>
                    </tr>

                    <tr class="area">
                        <td>现有方案：</td>
                        <td colspan="3">
                            <textarea id="nowSolution"></textarea>
                        </td>
                    </tr>
                    <tr class="area">
                        <td>建议方案：</td>
                        <td colspan="3">
                            <textarea id="sugSolution"></textarea>
                        </td>
                    </tr>
                    <tr class="area">
                        <td>附件：</td>
                        <td colspan="3">
                            <a href="javascript:;" class="a-upload" id="fileUpload"><input id="file" value="请选择" type="file"/>点击这里上传</a>
                            <p class="format">支持的格式有：JPG，PNG，PDF，PPT，XLSX，XLS，CSV，DOCX，DOC，ZIP</p>                             <p class="format">文件名不能包含*、#等特殊符号</p>
                            <ul class="addAttachmentList" id="addAttachmentList"> 
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="buttons">
                <a class="cancel" href="pm-need-list.html">取消</a>
                <a onclick="commit(this)">提交</a>
            </div>
        </div>
    </div>
</div>
<script src='../js/jquery.min.js'  type="text/javascript"></script>
<script src="../js/jquery.cookie.js"></script>
<script src="../js/common.js"></script>

<script type="text/javascript">
    _API.getTypeList('typeList')
        .getProductList('productList',false,true)
        .getPlatformList('platformList')
        .getLevelList('levelList');

    // 上传文件
    var attachment = new attachment();
    attachment.init({
        fileUpload:$('#fileUpload'),
        addAttachmentList:$('#addAttachmentList')
    });


    //修改需求来源
//    var goEditSource = $('#goEditSource');
    var searchBox = $('#searchBox');
    var existSourceBox = $('#existSourceBox');
//    var giveUp = $('#giveUp');
    var goSearchBtn = $('#goSearchBtn');
    var keyMatchSelect = $('#keyMatchSelect');
    goSearchBtn.on('click',function () {
        var _val = $(this).siblings('input').val();
        if(_val.length < 2) return;
        _API.checkProNameList('keyMatchSelect',0,true,_val)
    })



    var needName = $('#needName');
        scenario = $('#scenario');
    needName.focus(function(){
        needName.removeClass('error-i');
    })
    scenario.focus(function(){
        scenario.removeClass('error-i');
    })

    var isClick = false;
    function commit(that) {
        if(needName.val() == ''){
            needName.addClass('error-i');
            return
        } 
        if( scenario.val() == ''){
            scenario.addClass('error-i');
            return;
        }

        var attachment = [];
        var li = $('#addAttachmentList').find('li');
        if(li.length >= 1){
            li.each(function(){
                attachment.push( $(this).attr('rel') );
            })
        }

        if($('#keyMatchSelect').find('option:selected').text() == '请选择'){
            alert('请选择来源');
            return false
        }
        if($('#productList').find('option:selected').text() == '请选择'){
            alert('请选择产品！');
            return false
        }
        if($('#functionList').find('option:selected').text() == '请选择'){
            alert('功能模块！');
            return false
        }
        if($('#needSide').find('option:selected').text() == '请选择'){
            alert('请选择需求方');
            return false
        }
        var url  = _ip+'/original/addRequire';
        var data = {
            "creater":$.cookie('username'),
            "customerId":$('#needSide').val(),
            "feature":$('#functionList').val(),
            "name":$('#needName').val(),
            "nowSolution":$('#nowSolution').val(),
            "plat": $('#platformList').val(),
            "product": $('#productList').val(),
            "projectId":$('#keyMatchSelect').val(),
            "scenario": $('#scenario').val() || null,
            "sugSolution": $('#sugSolution').val() || null,
            "type": $('#typeList').val(),
            "attachment":attachment.join(''),
            "level":$('#levelList').val(),
            "status":'待处理'
        }
        if(isClick) return;
        $(that).addClass('sending');
        isClick = true;

        $.ajax({
            url:url,
            type : "POST",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            dataType: 'json',
            contentType:'application/json',
            data:JSON.stringify(data),
            success: function(data) {
                if(data.message === 'LOGIN') {
                    window.location.href = 'user-login.html';
                    return false;
                }
                if(data.success){

                    location.href = 'pm-need-list.html';
                }else{
                    $(that).removeClass("sending")
                    isClick = false;
                    alert('上传失败, 请稍后重试！');
                }
            }
        })
   }

</script>
</body>
</html>